package com.ask.langchain4j_springboot.config;

import com.ask.langchain4j_springboot.service.RefundToolsService;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.chat.StreamingChatLanguageModel;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.SystemMessage;
import dev.langchain4j.service.TokenStream;
import dev.langchain4j.service.UserMessage;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ChatAssistantConfig {
    public interface RefundAssistant {
        String chat(String message); // 普通对话

        @SystemMessage("扮演退票助手")
        TokenStream stream(@UserMessage String message); // 流式对话
    }

    @Bean
    public RefundAssistant refundAssistant(ChatLanguageModel chatLanguageModel, StreamingChatLanguageModel streamingChatLanguageModel,
                                           RefundToolsService refundToolsService) {
        ChatMemory chatMemory = MessageWindowChatMemory.withMaxMessages(10);
        RefundAssistant refundAssistant = AiServices.builder(RefundAssistant.class)
                .chatLanguageModel(chatLanguageModel)
                .streamingChatLanguageModel(streamingChatLanguageModel)
                .chatMemory(chatMemory)
                .tools(refundToolsService)
                .build();
        return refundAssistant;
    }
}
